package com.alamiya.security.service.impl;

import com.alamiya.security.entity.PublicRoleAuthorityRelation;
import com.alamiya.security.mapper.PublicRoleAuthorityRelationMapper;
import com.alamiya.security.service.IPublicRoleAuthorityRelationService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author hehaoqi
 * @since 2021-02-09
 */
@Service
public class PublicRoleAuthorityRelationServiceImpl extends ServiceImpl<PublicRoleAuthorityRelationMapper, PublicRoleAuthorityRelation> implements IPublicRoleAuthorityRelationService {

    @Override
    public List<String> listAuthorityIdsByRoleId(String roleId) {
        List<String> authorityIds = list(new LambdaQueryWrapper<PublicRoleAuthorityRelation>()
                .eq(PublicRoleAuthorityRelation::getRoleId, roleId))
                .stream()
                .map(PublicRoleAuthorityRelation::getAuthorityId)
                .collect(Collectors.toList());
        return Objects.isNull(authorityIds) ? Collections.EMPTY_LIST : authorityIds;
    }
}
